/**
 * 用某个值初始化数组.
 * @param val (必须) 初始化值
 * @param startidx (可选,默认0),  起始位置
 * @param len (可选,默认从 startidx 到数组所有元素) 长度
 */
Array.prototype.init = function(val, startidx, len){
    if (startidx == undefined || startidx.constructor != Number || startidx < 0)
        startidx = 0;
    if (len == undefined || len.constructor != Number || len < 0)
        len = this.length - startidx;
    var totallen = startidx + len;
    if (val.constructor == Function){
        for (let idx = startidx; idx < totallen; idx++)
            this[idx] = new val();
    }else{
        for (let idx = startidx; idx < totallen; idx++)
            this[idx] = val;
    }
};

/**
 * 用从目标数组拷贝元素.
 * @param array (必须) 目标数组
 * @param startIndex (可选,默认0),  目标数组起始位置
 * @param oriIndex (可选,默认0),  this数组起始位置
 * @param len (可选,默认从 startIndex 到目标数组所有元素) 长度
 */
Array.prototype.copyFrom = function(array, startIndex, oriIndex, len){
    if (array.constructor != Array)
        return;
    if (startIndex == undefined || startIndex.constructor != Number || startIndex < 0)
        startIndex = 0;
    if (oriIndex == undefined || oriIndex.constructor != Number || oriIndex < 0)
        oriIndex = 0;
    if (len == undefined || len.constructor != Number || len < 0)
        len = array.length - startIndex;
    let totallen = startIndex + len;
    let div = oriIndex - startIndex;
    for (let idx = startIndex; idx < totallen; idx++)
        this[idx + div] = array[idx];
};

/**
 * 拷贝元素到目标数组.
 * @param array (必须) 目标数组
 * @param startIndex (可选,默认0),  this数组起始位置
 * @param tgtIndex (可选,默认0),  目标数组起始位置
 * @param len (可选,默认从 startIndex 到this数组所有元素) 长度
 */
Array.prototype.copyTo = function(array, startIndex, tgtIndex, len){
    if (array.constructor != Array)
        return;
    if (startIndex == undefined || startIndex.constructor != Number || startIndex < 0)
        startIndex = 0;
    if (tgtIndex == undefined || tgtIndex.constructor != Number || tgtIndex < 0)
        tgtIndex = 0;
    if (len == undefined || len.constructor != Number || len < 0)
        len = this.length - startIndex;
    let totallen = startIndex + len;
    let div = tgtIndex - startIndex;
    for (let idx = startIndex; idx < totallen; idx++)
        array[idx + div] = this[idx];
};